Skip to content

feat(ts): generate <Proto>Client / dispatcher against @comline/runtime - #8

Merged
Kinflou merged 1 commit into
mainfrom
feat/ts-generate-client
Sep 2, 2026
Merged

feat(ts): generate <Proto>Client / dispatcher against @comline/runtime#8
Kinflou merged 1 commit into
mainfrom
feat/ts-generate-client

Conversation

@Kinflou

@Kinflou Kinflou commented Sep 2, 2026

Copy link
Copy Markdown
Member

The TypeScript code generator now emits the full RPC shape for a protocol, not just method signatures — mirroring what the Rust generator does.

Emitted
error <Name> export interface <Name> (wire payload) + export class <Name>Error extends Error with .data and a static .ordinal
<Proto><Fn>Params one interface per function with args
<Proto> provider interface — Promise-returning methods, @throws {<Name>Error} JSDoc
<PROTO>_CALLS the ordered call table
<Proto>Dispatcher implements Dispatch — decode → run impl → map a caught <Name>Error to reply.err(ordinal, …); one-way calls leave the reply empty
<Proto>Client + static connect() (handshake from IR_HASH); one method per function, Envelope<Name>Error / RuntimeError.remote
serve<Proto>(impl, transport, codec, framing?) the provider helper

Framing follows @framing on the protocol / the package default_framing (same recognition as the Rust generator): DatagramFraming default, JsonRpcFraming for jsonrpc.

Executable check: runtime/test/generated/chat.ts is real generator output (blessed by generate.rs; TS_BLESS=1 to refresh). runtime/test/generated.test.ts type-checks it and runs a client ⇆ provider round-trip over duplex() — a call, a list call, a raised RejectedError, a one-way notify, a () return. 21 runtime tests + 7 codegen tests green.

Companion generation PR re-blesses the protocol/typescript.ts conformance golden.

Next: lib mode (npm package output).

The TypeScript `code` generator now emits the full RPC shape for a
`protocol`, not just the method signatures:

  - `error <Name>` -> `export interface <Name>` (wire payload) + `export
    class <Name>Error extends Error` carrying `.data` and a static
    `.ordinal` (the throwable a provider raises / a client re-raises).
  - `<Proto><Fn>Params` interface per function with arguments.
  - `<Proto>` provider interface: `Promise`-returning methods, `@throws
    {<Name>Error}` JSDoc.
  - `<PROTO>_CALLS` const table.
  - `<Proto>Dispatcher implements Dispatch` — decode params, run the impl,
    map a caught `<Name>Error` to `reply.err(ordinal, ...)`, one-way calls
    leave the reply empty.
  - `<Proto>Client` + static `connect()` (runs the handshake from
    `IR_HASH`): one method per function, decoding the `Envelope`, mapping
    `env.err.id` back to `<Name>Error` or `RuntimeError.remote`.
  - `serve<Proto>(impl, transport, codec, framing?)` helper.

Framing follows `@framing` on the protocol / the package `default_framing`
(same recognition set as the Rust generator): `DatagramFraming` default,
`JsonRpcFraming` for `jsonrpc`.

`runtime/test/generated/chat.ts` is real generator output (blessed by
`generate.rs`, `TS_BLESS=1` to refresh); `runtime/test/generated.test.ts`
type-checks it and runs a client ⇆ provider round-trip over `duplex()`.
@Kinflou
Kinflou merged commit 71ffffc into main Sep 2, 2026
4 checks passed
@Kinflou
Kinflou deleted the feat/ts-generate-client branch September 2, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant